package cn.achuan.spring.springcloud.demo;

import com.netflix.zuul.ZuulFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER;
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE;

public class PreTypeZuulFilter extends ZuulFilter {
    private Logger logger = LoggerFactory.getLogger(PreTypeZuulFilter.class);

    // 返回该过滤器的类型
    @Override
    public String filterType() {
        return PRE_TYPE;
    }

    // 返回执行的顺序
    @Override
    public int filterOrder() {
        return PRE_DECORATION_FILTER_ORDER - 1;
    }

    // 判断是否需要执行该过滤器
    @Override
    public boolean shouldFilter() {
        return true;
    }

    // 所要执行的具体过滤动作
    @Override
    public Object run() {
        this.logger.info("This is pre-type zuul filter.");
        return null;
    }
}